#!/bin/bash

if [[ ! -e "GenshinImpact.exe" ]]; then
	echo "-- GenshinImpact executable not found. Wrong directory?"
	exit 1
fi

# Restore files that have a backup
FILE="UnityPlayer.dll"
CEXE="GenshinImpact_Data/upload_crash.exe"

if [[ -e "$FILE.bak" ]]; then
	# Restore from backup
	mv -f "$FILE.bak" "$FILE"
	echo "-- Restored $FILE"
else
	echo "-- Cannot restore '$FILE' (.bak not found)"
fi

if [[ -e "$CEXE" ]]; then
	echo "-- Crash reporter already exists"
else
	if [[ -e "$CEXE.bak" ]]; then
		# Restore from backup
		mv -f "$CEXE.bak" "$CEXE"
		echo "-- Restored the crash reporter"
	else
		echo "-- Cannot restore '$CEXE' (.bak not found)"
	fi
fi


echo "-- Removing all newly added files"
# The error messages for inexistent files are intended
rm "launcher.bat"
rm "mhyprot2_running.reg"

# dxvk files
rm *.dxvk-cache
rm *_d3d9.log
rm *_d3d11.log
rm *_dxgi.log


echo "==> Patch reverted."
exit 0
